import React, { Component } from 'react'
import { Form, Input, Button, } from 'antd';
import {connect} from 'react-redux'
import axios from 'axios'


class Index extends Component {
    
    render() {
        const layout = {
            labelCol: { span: 8 },
            wrapperCol: { span: 10 },
        }
        const tailLayout = {
            wrapperCol: { offset: 8, span: 16 },
        }
        const onFinish = values => {
            console.log('Success:', values);
            this.props.login(values)
        }
        const onFinishFailed = errorInfo => {
            console.log('Failed:', errorInfo);
        }      
        return (
            <div>
                <Form
                {...layout}
                name="basic"
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                >
                <Form.Item
                    label="账号"
                    name="username"
                    rules={[{ required: true, message: '请输入账户名!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: '请输入密码!' }]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item
                    label="再次输入密码"
                    name="password2"
                    rules={[{ required: true, message: '请确认密码!' }]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item {...tailLayout}>
                    <Button type="primary" htmlType="submit">
                    注册
                    </Button>
                </Form.Item>
                </Form>
            </div>
        )
    }
}
let mapStateToProps =(state) => {
    return {
        
    }
}
let mapDispatchToProps =(dispatch,props) => {
    return {
        login(obj){
            dispatch(() =>{
                axios.post('/worklogin',{
                    phone:obj.username,
                    password:obj.password
                }).then(res =>{
                    // console.log(222,obj)
                    if(res.data.code === 1){
                        console.log('注册成功')
                        // console.log(props)
                        props.history.push('/enter')
                    }else{
                        console.log('注册失败')
                    }  
                })
            })
        }
    }
}
export default connect(mapStateToProps,mapDispatchToProps)(Index)
